package com.caifu.mapper;

import com.caifu.pojo.YlPaymentRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * <p>
 * 缴费记录表 Mapper 接口
 * </p>
 *
 * @author GZ
 * @since 2020-11-06
 */
public interface YlPaymentRecordMapper extends BaseMapper<YlPaymentRecord> {

    //获取用户实缴费用
    @Select("select IFNULL(sum(PAYMENT_COUNT),0) from yl_payment_record y where y.STATUS=1 and user_no=#{userNo}")
    double getUserTotalPayAmt(@Param("userNo") String userNo);

    //通过缴费记录id获取该条缴费的已扣金额，未扣金额
    @Select("select (select IFNULL(sum(r.PAY_AMT),0) from yl_payment_detail_record r where r.RECORD_ID=y.id)as payAmt, y.PAYMENT_COUNT-(select IFNULL(sum(r.PAY_AMT),0)payAmt from yl_payment_detail_record r where r.RECORD_ID=y.id) as unpayAmt from yl_payment_record y where y.id=#{recordId} and y.`STATUS`='1';")
    Map<String,Object> getPaymentRecordSum(@Param("recordId") int recordId);

}
